package com.lyl.domaindemo.application.export;

import com.lyl.domaindemo.Infrastructure.utils.ApplicationContextUtil;
import com.lyl.domaindemo.domain.export.CommonExport;
import com.lyl.domaindemo.domain.export.CommonExportService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Component;

import java.lang.reflect.Method;

/**
 * @author lyl
 * @date 2023/6/8
 */
@Component
@Slf4j
public class CommonExportUseCase {

    private final CommonExportService commonExportService;

    public CommonExportUseCase(CommonExportService commonExportService) {
        this.commonExportService = commonExportService;
    }


    public Object commonExport(String id,Pageable pageable) {
        CommonExport commonExport = commonExportService.commonExport(id);
        try {
            Class<?> aClass = Class.forName(commonExport.getClassName());
            Object bean = ApplicationContextUtil.getBean(aClass);
            Method method = aClass.getDeclaredMethod(commonExport.getMethod(), Pageable.class);
            log.info(method.getName());
            return method.invoke(bean,pageable);
        } catch (Exception e) {
            log.error("========");
        }
        return null;
    }
}
